<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 500px;
            height: 100px;
            border: 5px solid pink;
        }
        #yy{
            width: 500px;
            height: 100px;
            border: 5px solid pink;
        }
    </style>
</head>
<body>
    <input type="text" id="username">&nbsp;
    <button id="btn">复制</button>
    <div id="box">     
    </div> 
    <!-- //2 有个button,有个h2(封校三天 快乐无边),当点击button时会显示文字，再次点击会文字会消失。 -->
    <button id="xx">隐藏</button>
    <div id="yy">     
    </div> 
</body>
<script>
    var yc = document.getElementById('xx');
    var index=0;
     xx.onclick= ()=> {
        if (index==0) {
        var yy=document.getElementById('yy');
        var newH2 = document.createElement('h2');
        var txt = document.createTextNode('封校三天 快乐无边');
       newH2.appendChild(txt)
        yy.appendChild(newH2);
        index++;
        }
        else{
         var div=   document.getElementById('yy');
            div.innerText=''
               index--;
        }
        
       
    }



    var username = document.querySelector('#username');
    var btn = document.querySelector('#btn');
    btn.onclick = ()=>{
        document.getElementById('box').innerHTML = '<h2>'+username.value+'</h2>';
        username.value = '';
    }
</script>
</html>